home *** CD-ROM | disk | FTP | other *** search
- Path: lrz-muenchen.de!news
- From: watzka@stat.uni-muenchen.de (Kurt Watzka)
- Newsgroups: comp.lang.c
- Subject: Re: variable length string
- Date: 6 Feb 1996 15:35:01 GMT
- Organization: Leibniz-Rechenzentrum, Muenchen (Germany)
- Distribution: world
- Message-ID: <4f7sf5$emk@sparcserver.lrz-muenchen.de>
- References: <4f5s97$8sho@tigger.cc.uic.edu> <9602052314.AA18664@dxmint.cern.ch> <4f6ma1$613e@tigger.cc.uic.edu>
- NNTP-Posting-Host: sun2.lrz-muenchen.de
-
- Qi Zeng <zeng@sunphy1.phy.uic.edu> writes:
-
- >Dan Pop <danpop@mail.cern.ch> wrote:
- >>
- >> Qi Zeng <zeng@sunphy1.phy.uic.edu> writes:
- >> > >Suppose you want to read from stdin a string, but you do not know how
- >> >long it will be. You have to assign the string to some char*,
- >>
- >> Use fgets with a reasonably sized buffer. After reading the string,
- >> use strlen to find out its real length, malloc the right amount of memory
- >> and copy the string there (dropping the terminating '\n').
- >> > Dan
- >
- >Thanks.
-
- >And yes, it is a way to do that. But how to deal with the space you
- >malloced? Say you return a char *, which points to the space you jsut
- >malloced. When do you free them?
-
- Aehm, when you don't need it any more, maybe? This question should
- definitely be in the "other" FAQ.
-
- Managing your dynamically allocated memory is a burden that you have
- to bear to avoid the need for "garbage collection" or something
- similar.
-
- Kurt
- --
- | Kurt Watzka Phone : +49-89-2180-6254
- | watzka@stat.uni-muenchen.de
- | ua302aa@sunmail.lrz-muenchen.de
-